# -*- coding: utf-8 -*-
"""
Created on Sun Aug 16 11:05:44 2020

@author: Lenovo
"""


import pandas as pd
import numpy as np
import datetime,os
def AVE_REAL(): #实时电量平均值
    pwd = os.getcwd() #获取当前文件夹路径
    father_path=os.path.abspath(os.path.dirname(pwd)+os.path.sep+".") #获取父文件夹路径
    dict_d=pd.read_excel(father_path+"\8月现货数据.xlsx",sheet_name=None,header=[0,1]) # 获取所有sheet_name表的数据，字典,键是日期，值是表数据
    def isNaN(num): # 判断空值
        return num != num
    dict_s={}
    I=0
    for i in dict_d:
        list_df=np.array(dict_d[i]['实时电量']).tolist() # 将实用电量转为列表数据
        if isNaN(list_df[0][0]) == True:
            pass
        else:
            l=[]
            for k in list_df:
                l.append(k[0])
            dict_s[str(i)]=l
        I=i
    l_min=np.array(dict_d[I]['时间']).tolist()
    l=[]
    for i in l_min:
        l.append(i[0])
    data=pd.DataFrame(dict_s,index=l)
    data['均值']=data.mean(1)
    r_time=datetime.datetime.now().strftime('%Y-%m-%d')
    data.to_excel('实时电量均值('+r_time+').xlsx')
    print('实时电量均值表搞定了')